<?php
class System_Spam {

	private $resTrie = null;

	private $init_words = array(
		'QQ','扣扣','1','2','3','4','5','6','7','8','9','0','手机','微信','加我',
		'⑦','③','⑩','⑦','⑧','⑧','③','⑧','wx','wechat','危','信','号','weixin',
		'一','二','三','四','五','六','七','八','九','零','凌','壹','陆','伍','肆','贰','one','two',
		'three','four','five','six','seven','eight','nine','zero','1⃣','2⃣','3⃣','7⃣','8⃣','9⃣',
		'卸载','收费','扣费','垃圾软件','骗子','流氓','②','④','红豆','⑤','①','⑥'
	);

	function __construct(){
		$resTrie = trie_filter_new(); 
		foreach ($this->init_words as $k => $v) {
		    trie_filter_store($resTrie, $v);
		}
		$file_name = __DIR__ . '/blackword.tree';

		#判断文件是否存在,及更新时间,每天更新一次
		if(!file_exists($file_name)){
			trie_filter_save($resTrie, $file_name);
		}elseif(filemtime($file_name) < time() - 24*3600 ){
			trie_filter_save($resTrie, $file_name);
		}

		$this->resTrie = trie_filter_load(__DIR__ . '/blackword.tree');

	}

	function search($content){
		return trie_filter_search_all($this->resTrie, $content);
	}
}
